﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class CMD_NewPositionInfo : System.Web.UI.UserControl
    {
        private IJobSiteBLL jsBLL = new JobSiteBLL();
        private IClassBLL cBLL = new ClassBLL();
        private IPositionTypeBLL ptBLL = new PositionTypeBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        public void SetValue(object date)
        {
            txtStartDate.SetValue(date);
        }

        public string GetStringValue()
        {
            string strDate = txtStartDate.GetStringValue();

            return strDate;
        }
        private void bindClasscombo()
        {            
            IList<ClassInfo> infoList = cBLL.ListClasses(posTypeCombo.SelectedValue);

            classCombo.DataSource = infoList;
            classCombo.DataBind();
        }

        private void bindJobSiteCombo()
        {
            IList<JobSiteInfo> infoList = jsBLL.ListJobSiteByTypes(SystemInfo._JobsiteExternal);

            jobSiteCombo.DataSource = infoList;
            jobSiteCombo.DataBind();
        }

        private void bindPosTypeCombo()
        {
            
            IList<PositionTypeInfo> infoList = ptBLL.ListPositionTypes(Convert.ToInt32(Session["EMPTYPE"].ToString()));

            posTypeCombo.DataSource = infoList;
            posTypeCombo.DataBind();
        }
        protected void btnFindPos_Click(object sender, ImageClickEventArgs e)
        {
            string st = HidePos.Value;
            if (st == "")
                return;

            RecruitNewEmployeeBLL eBLL = new RecruitNewEmployeeBLL();
            PositionInfo posInfo = new PositionInfo();
            IList<PositionInfo> infoList = eBLL.GetPositions(Int32.Parse(st));

            if (infoList.Count > 0)
            {
                posInfo = infoList[0];
                txtPosition.Text = posInfo.Name;
                txtPosRef.Text = posInfo.RefNo;
                posTypeCombo.SelectedValue = posInfo.PositionType.Sequence.ToString();
                bindClasscombo();
                jobSiteCombo.SelectedValue = posInfo.JobSite.Sequence.ToString();
            }
        }
        protected void btnFindPos_Load(object sender, EventArgs e)
        {
            btnFindPos.Attributes.Add("OnClick", "LinkMDdetail(" + HidePos.ClientID + "," + "'Forms/DialogPositions.aspx','../frmIframe.html',700,500)");
        }

        protected void posTypeCombo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            bindClasscombo();
        }

        protected void classCombo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {          
            SalaryGroupBLL salBLL = new SalaryGroupBLL();
            DataTable dt = new DataTable();

            dt = salBLL.SelectSalaryGroup(classCombo.SelectedValue.Length > 0 ? Int32.Parse(classCombo.SelectedValue) : (int?)null);

            if (dt.Rows.Count > 0)
            {
                lblSalaryLevel.Text = string.Format("{0:N0}", dt.Rows[0]["sal_min"]) + " - " + string.Format("{0:N0}", dt.Rows[0]["sal_max"]);
            }
            else
                lblSalaryLevel.Text = "";
            
        }

        protected void posTypeCombo_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            bindPosTypeCombo();
        }

        protected void jobSiteCombo_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            bindJobSiteCombo();
        }
    }
}